package com.fitness.front.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fitness.front.convertor.CourseCategoryConvertor;
import com.fitness.front.mapper.CourseCategoryMapper;
import com.fitness.front.modal.course.dto.CourseCategoryDto;
import com.fitness.front.modal.course.entity.CourseCategory;
import com.fitness.front.modal.course.params.CourseCategoryPageQueryParams;
import com.fitness.front.modal.course.vo.CourseCategoryVO;
import com.fitness.front.service.ICourseCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CourseCategoryServiceImpl extends ServiceImpl<CourseCategoryMapper,CourseCategory> implements ICourseCategoryService {

    private final CourseCategoryConvertor courseCategoryConvertor;

    @Override
    public boolean updateCourseCategory(CourseCategoryDto equipmentDto) {
        return updateById(courseCategoryConvertor.dto2Entity(equipmentDto));
    }

    @Override
    public boolean addCourseCategory(CourseCategoryDto equipmentDto) {
        return save(courseCategoryConvertor.dto2Entity(equipmentDto));
    }

    @Override
    public Page<CourseCategoryVO> getCourseCategoryPage(CourseCategoryPageQueryParams queryParams) {
        // 参数构建
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Page<CourseCategory> page = new Page<>(pageNum, pageSize);

        // 查询数据
        Page<CourseCategory> coachBoPage = this.baseMapper.getCourseCategoryPage(page, queryParams);

        return courseCategoryConvertor.entity2Vo(coachBoPage);
    }

    @Override
    public List<CourseCategoryVO> getIndexCategory() {
        return courseCategoryConvertor.entities2Vo(this.baseMapper.getIndexCategory());
    }
}
